from abc import ABCMeta
from os.path import dirname, realpath, basename, join
from typing import Dict

from mg_app_framework import AppConfigBasic, AppType


class ConfigStore(AppConfigBasic):
    # ==================== DON'T MODIFY THE CODE BETWEEN COMMENT LINE ====================

    work_dir = dirname(dirname(dirname(realpath(__file__))))
    app = basename(dirname(realpath(__file__)))
    log_path = join(work_dir, 'log', app + '.log')
    uuid_path = join(work_dir, '.appid')

    def get_module_dir(self):
        return dirname(realpath(__file__))

    def get_log_path(self):
        return self.log_path

    def get_uuid_path(self):
        return self.uuid_path

    def get_data(self):
        return self.data

    # ==================== DON'T MODIFY THE CODE BETWEEN COMMENT LINE ====================

    data = {
        'app_group': '应用组件',
        'app_name': 'MES日志查询系统',
        "app_module_name": "service_log_viewer",
        'app_type': AppType.user,
        'app_version': "0.0.1",
        'data': {}
    }

    def get_app_port(self):
        return 30189

    def connect_admin(self):
        return True

    def get_admin_host(self):
        return "192.168.0.218"


class RedisConfigBasic(metaclass=ABCMeta):
    def get_redis_host(self):
        return "127.0.0.1"

    def get_redis_port(self):
        return 6379

    def get_redis_username(self):
        pass

    def get_redis_password(self):
        return "realtech@123"

    def reconnect_interval(self):
        """
        :return:重连redis时间间隔, 默认 5 秒

        """
        return 5

    def get_redis_conn_pool_config(self) -> Dict:
        return {"socket_connect_timeout": 5, "max_connections": 50}
